package project_2;

import java.net.ServerSocket;
import java.net.Socket;


public class PGO_node{
	private static int listener_port = 4567;
	private static int port_num = -1;		 
	
	 public static void main(String argv[]) throws Exception{		 
		 //Pair<int, int>[] neighbor_ID_arr = new Pair<int, int>[4]; // Array of neighbor node IDs
	     Pair<Integer, Integer> a = new Pair<Integer, Integer>(1,2);	
	     port_num = Integer.parseInt(argv[0]);
		 Socket senderSocket;
		 //ServerSocket listenerSocket = new ServerSocket(listener_port);
		 //Thread.currentThread().sleep(6000);
		 System.out.println(port_num + a.toString());	
		 Thread test_run = new Thread(new testRun());		 
		 test_run.start();
		 Thread testMessage = (new Thread(new SleepMessages()));
		 testMessage.start();		
		 
	 }

}

class testRun implements Runnable{

	@Override
	public void run() {
		// TODO Auto-generated method stub
		for (int i=0; i<10000; i++){
			System.out.println(i + " Hello Thread!");
			try {
				Thread.currentThread().join();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}

class SleepMessages implements Runnable{

	 private String importantInfo[] = {
	            "Mares eat oats",
	            "Does eat oats",
	            "Little lambs eat ivy",
	            "A kid will eat ivy too"
	        };
	@Override
	public void run() {
		// TODO Auto-generated method stub
        for (int i = 0; i < importantInfo.length; i++) {
            //Pause for 4 seconds
            try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return;
			}
            //Print a message
            System.out.println(importantInfo[i]);            
        }
        Thread.currentThread().notify();
	}
	
}


